package com.packet.controller;

import com.packet.pojo.Customs;
import com.packet.pojo.ManagerApplication;
import com.packet.pojo.Trip;
import com.packet.service.GetFromStaffService;
import com.packet.service.ManagerApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author L
 */
@Controller
public class ManagerApplicationController {

    @Autowired
    ManagerApplicationService managerApplicationService;

    @RequestMapping("/maa")
    public String ApplicationList(Model model, HttpSession session){
        Integer sid = (Integer)session.getAttribute("sid");
        List<ManagerApplication> managerApplications = managerApplicationService.selectAll(sid);
        model.addAttribute("managerApplications",managerApplications);
        return "maa/list";
    }

    @RequestMapping("/mar")
    public String ReimburseList(Model model, HttpSession session){
        Integer sid = (Integer)session.getAttribute("sid");
        List<ManagerApplication> managerApplications = managerApplicationService.selectReimburseAll(sid);
        model.addAttribute("managerApplications",managerApplications);
        return "maa/reimburseList";
    }

    @PostMapping("/fuzzyQuery")
    public String FuzzyQuery(Model model,HttpSession session,@RequestParam("sName") String sName){
        Integer sid = (Integer)session.getAttribute("sid");
        sName = "%" + sName + "%";
        List<ManagerApplication> managerApplications = managerApplicationService.selectByConditionSingle(sid,sName);
        model.addAttribute("managerApplications",managerApplications);
        return "maa/list";
    }

    @PostMapping("/fuzzyQuery2")
    public String FuzzyQuery2(Model model,HttpSession session,@RequestParam("sName") String sName){
        Integer sid = (Integer)session.getAttribute("sid");
        sName = "%" + sName + "%";
        List<ManagerApplication> managerApplications = managerApplicationService.selectByConditionSingle2(sid,sName);
        model.addAttribute("managerApplications",managerApplications);
        return "maa/reimburseList";
    }


    @Autowired
    GetFromStaffService getFromStaffService;
    ///staff/detailTrip/{bid}(bid=${managerApplication.getBId()})
    @RequestMapping("/manager/TripToManager/{bid}")
    public String getDetailTrip(@PathVariable("bid") Integer bid,Model model){
        Trip detailTrip = getFromStaffService.getTripToManager(bid);
        List<Customs> detailCustoms = getFromStaffService.getCustomsToManager(bid);
        List<Customs> detailCustomsThen = getFromStaffService.getCustomsThenToManager(bid);

        model.addAttribute("detailTrip",detailTrip);
        model.addAttribute("detailCustoms",detailCustoms);
        model.addAttribute("detailCustomsThen",detailCustomsThen);

        return "maa/detailTrip";
    }
}
